<?php
namespace V1\Model;
use Think\Model;
/**
 * 碎片表操作
 */
class TagModel extends Model {
    /**
    * 数据表前缀
    * @var string
    */
   protected $tablePrefix = MTCORE_TABLE_PREFIX;
   /**
    * 数据库连接
    * @var string
    */
   protected $connection = MTCORE_DB_DSN;
    /**
     * 获取马蹄指数信息
     * @return array 列表
     */
    public function queryList($where = array(), $order = 'C1D desc'){
       $querysql="SELECT stockcode,stockname," .
       		"SUM( CASE WHEN DATE_ADD(publishdate,INTERVAL 2 HOUR) >= NOW() THEN newscount ELSE 0 END ) AS C2H " .
       		",SUM( CASE WHEN DATE_ADD(publishdate,INTERVAL 24 HOUR) >= NOW() THEN newscount ELSE 0 END) AS C1D" .
       		",SUM( CASE WHEN DATE_ADD(publishdate,INTERVAL 2 DAY) >= NOW() THEN newscount ELSE 0 END ) AS C2D" .
       		",SUM( CASE WHEN DATE_ADD(publishdate,INTERVAL 7 DAY) >= NOW() THEN newscount ELSE 0 END) AS C1W" .
       		",SUM( CASE WHEN DATE_ADD(publishdate,INTERVAL 1 MONTH) >= NOW() THEN newscount ELSE 0 END) AS C1M" .
       		",SUM( CASE WHEN DATE_ADD(publishdate,INTERVAL 2 HOUR) >= NOW() THEN sentiment ELSE 0 END ) AS S2H" .
       		",SUM( CASE WHEN DATE_ADD(publishdate,INTERVAL 24 HOUR) >= NOW() THEN sentiment ELSE 0 END) AS S1D" .
       		",SUM( CASE WHEN DATE_ADD(publishdate,INTERVAL 2 DAY) >= NOW() THEN sentiment ELSE 0 END ) AS S2D" .
       		",SUM( CASE WHEN DATE_ADD(publishdate,INTERVAL 7 DAY) >= NOW() THEN sentiment ELSE 0 END) AS S1W" .
       		",SUM( CASE WHEN DATE_ADD(publishdate,INTERVAL 1 MONTH) >= NOW() THEN sentiment ELSE 0 END) AS S1M  " .
       		"FROM stock_tag_hour as A  where 1=1 ";
       
        if(!empty($where['A.stathour'])) {
        	$querysql = str_replace("NOW()","'".$where['A.stathour']."'",$querysql);
        	$querysql .= " and publishdate<='".$where['A.stathour']."' ";
        }

	if(!empty($where['A.stocktype']) && $where['A.stocktype'] == 'HK') {
                $querysql.= " and  length(A.stockcode)=5  ";	
        }else {
        	$querysql.= " and  length(A.stockcode)=6  ";
        }
        
        $querysql.= " GROUP BY stockcode,stockname ORDER BY ".$order;
      
        $list= $this->query($querysql); 
        return $list;         
     
    }

    public  function getNewList($list,$stathour,$sortkey="C1D"){
	    $newlist = array();
	    
	    return $newlist;	    
    }
    
}
